package tv.geir.slackspace.common;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.List;

import net.jini.core.entry.UnusableEntryException;
import net.jini.core.transaction.Transaction;
import net.jini.core.transaction.TransactionException;
import net.jini.space.JavaSpace;
import tv.geir.slackspace.matching.Template;

public interface SlackSpace extends JavaSpace {
	SlackLease write( Serializable entry, Transaction txn, long leaseTime ) throws RemoteException, TransactionException;
	
	Serializable read( Template t, Transaction txn, long timeout ) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException ;
	
	Serializable take( Template t, Transaction txn, long timeout ) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException ;
	
	Serializable readIfExists( Template t, Transaction txn, long timeout ) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException ;
	
	Serializable takeIfExists( Template t, Transaction txn, long timeout ) throws UnusableEntryException, TransactionException, InterruptedException, RemoteException ;
	
	/**
	 * Finds and returns a copy of all matching entries. 
	 * @param t
	 * @return
	 */
	List<Serializable> readAll( Template t );
	
	List<Serializable> takeAll( Template t );
	
	/**
	 * Add this package and all subpackages to the moveable code.
	 * @param packageName
	 */
	public void addPackage( String packageName );
	
	void disconnect();
	
	public static final int DEFAULT_PORT = 8700;
}
